If a proto with the name typename as proto is already in the list, replace that entry (destroying the old entry), otherwise add a new entry.
Return the position of the added/modified entry.
The interface is not updated: have to avoid the interface in this routine since the list is loaded and accessed on startup, and the interface is not loaded until it is required.
*/
- (int)addtolist:proto
{
id old;
int pos = [self findposinlist:[proto typename]];
if (pos<=0)
{
// New entry.
pos = -pos;
[list insertObject:proto at:pos];
[typematrix insertRowAt:pos];
}
else
{
// Modify entry.
old = [list replaceObjectAt:pos with:proto];
[old free];
}
return pos;
}
// Remove the proto with typename name and update the interface.
- (int)removefromlist:(char *)name
{
int pos = [self findposinlist:name];
if (pos>=0)
{
[list removeObjectAt:pos];
[typematrix removeRowAt:pos andFree:YES];
[typematrix sizeToCells];
// Select the entry that was previous to the deleted entry in the list.
if (pos==[typematrix cellCount]) pos--;
[typematrix selectCellAt:pos:0];
[typematrix display];
}
if ([typematrix cellCount]==0) [remove setEnabled:NO];